package com.erp.servlet;

import com.erp.bean.Order;
import com.erp.bean.OrderState;
import com.erp.service.OrderService;
import com.erp.service.OrderStateService;
import com.erp.service.impl.OrderServiceImpl;
import com.erp.service.impl.OrderStateServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author zch
 * 审批控制器
 */
@WebServlet("/examine.action")
public class ExamineServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //创建订单业务逻辑对象
        OrderService orderService = new OrderServiceImpl();
        /*//创建订单状态业务逻辑对象
        OrderStateService orderStateService = new OrderStateServiceImpl();*/
        //接收订单状态编号
        String oidstr = req.getParameter("oid");
        String sidstr = req.getParameter("sid");
        String gidstr = req.getParameter("gid");
        String countstr = req.getParameter("count");
        String eidstr = req.getParameter("eid");
        String type = req.getParameter("type");
        String gname = req.getParameter("gname");
        System.out.println(gname);
        int sid = Integer.valueOf(sidstr);
        int eid = Integer.valueOf(eidstr);
        int gid = Integer.valueOf(gidstr);
        int count = Integer.valueOf(countstr);
        System.out.println(sid);
        Order order = new Order();
        if(type.equals("1")&&sid==1){
            System.out.println(3);
            order.setSid(2);
            order.setOid(oidstr);
            order.setEid(eid);
            order.setGid(gid);
            order.setCount(count);
            boolean flag = orderService.update(order);
            System.out.println(flag);
            resp.sendRedirect("examinelist.action");
            if(type.equals("1")&&sid==4){
                System.out.println(2);
                order.setSid(5);
                order.setOid(oidstr);
                order.setEid(eid);
                order.setGid(gid);
                order.setCount(count);
                boolean flag1 = orderService.update(order);
                resp.sendRedirect("examinelist.action");
            }
        }else if(type.equals("2")&&sid==1||sid==4){
            System.out.println(1);
            order.setSid(3);
            order.setOid(oidstr);
            order.setEid(eid);
            order.setGid(gid);
            order.setCount(count);
            boolean flag1 = orderService.update(order);
            resp.sendRedirect("examinelist.action");
        }else {
            resp.sendRedirect("examinelist.action");
        }



    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
